package hlhj.fhp.tvlib.activitys

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.design.widget.TabLayout
import android.support.v4.app.Fragment
import android.support.v4.view.ViewPager
import com.bumptech.glide.Glide
import hlhj.fhp.tvlib.Contents
import hlhj.fhp.tvlib.R
import hlhj.fhp.tvlib.adapter.LivePagerAdp
import hlhj.fhp.tvlib.fragment.LiveCommentFgm
import hlhj.fhp.tvlib.fragment.LiveInfoFgm
import hlhj.fhp.tvlib.fragment.LiveTextFgm
import kotlinx.android.synthetic.main.activity_text_live_aty.*
import org.apache.cordova.LOG
import java.util.ArrayList

class TextLiveAty : BaseAty() {
    private lateinit var infoFgm: Fragment
    private lateinit var commentFgm: Fragment
    private lateinit var textImgFgm:LiveTextFgm
    private val fgmList= ArrayList<Fragment>()
    private var id=""
    private var thumb=""
    private lateinit var pagerAdp:LivePagerAdp
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        id=intent.getIntExtra("id",-1).toString()
//        tvTittle.text=intent.getStringExtra("tittle")
        supportActionBar!!.hide()
        thumb=intent.getStringExtra("thumb")
        LOG.e("fhp",thumb)
        Glide.with(this).load(Contents.IMG_URL+thumb).into(imgBg)
        btExit.setOnClickListener {
            finish()
        }
        doPager()
    }

    override fun getContentId(): Int {
        return R.layout.activity_text_live_aty
    }
    private fun doPager() {
        infoFgm=LiveInfoFgm.getInstence(id,2)
        commentFgm=LiveCommentFgm.getInstence(id)
        textImgFgm=LiveTextFgm.getInstentce(id)
        fgmList.add(infoFgm)
        fgmList.add(textImgFgm)
        fgmList.add(commentFgm)
        viewPager.offscreenPageLimit=4
        pagerAdp= LivePagerAdp(supportFragmentManager,fgmList)
        viewPager.adapter=pagerAdp

        tablayout.addOnTabSelectedListener(object :TabLayout.OnTabSelectedListener{
            override fun onTabReselected(tab: TabLayout.Tab?) {
            }

            override fun onTabUnselected(tab: TabLayout.Tab?) {
            }

            override fun onTabSelected(tab: TabLayout.Tab?) {
                viewPager.currentItem=tab!!.position
            }
        })

        viewPager.addOnPageChangeListener(object :ViewPager.OnPageChangeListener{
            override fun onPageScrollStateChanged(state: Int) {

            }

            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
            }

            override fun onPageSelected(position: Int) {
                tablayout.getTabAt(position)!!.select()
            }
        })
    }
}

